package com.apes.scm.masterdata.product.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = OrientationDiagramCategory.CONST_TABLE_NAME)
public class OrientationDiagramCategory extends BaseModel {


    public static final String CONST_TABLE_NAME = "orientation_diagram_category";


    @Id
    @Column(name = "id")
    @Comment("编码")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "方位图菜单")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "menu_id", referencedColumnName = "id", nullable = false)
    @Comment("方位图目录")
    private OrientationDiagramMenu menu;


    @Transient
    private OrientationDiagramMenu tempMenu;

    public OrientationDiagramMenu getTempMenu() {
        if (this.tempMenu != null) return tempMenu;
        if (this.menu == null) return null;
        return this.menu;
    }

    /***
     * 用于获取当前目录所有的目录图进行展示
     */
    @Transient
    private String parentMenus;

    public String getParentMenus() {
        if (this.menu == null) return null;
        return this.menu.getPathName();
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", referencedColumnName = "id", nullable = false)
    @Comment("配件名称")
    private Category category;


    @Comment("专用标记")
    @Column(name = "special_use",columnDefinition = ApesConst.FIELD_BOOLEAN_FALSE, nullable = false)
    private boolean specialUse;
}
